﻿using huqiang.Communication;
using huqiang.Core.HGUI;
using huqiang.Framework;
using huqiang.Framework.Http;
using huqiang.UIComposite;
using huqiang.UIModel;
using UnityEngine;

public class GameSystem : MonoBehaviour
{
    static GameSystem Instance;
    public string RemoteIP = "192.168.0.134";
    public int RemotePort = 8899;
    public TextAsset uiData;
    private void Awake()
    {
        if (Instance == null)
        {
            Instance = this;
            DontDestroyOnLoad(gameObject);
        }
        else
        {
            Destroy(gameObject);
        }
        //MovePath mp = new MovePath();
        //mp.damp = 0.997f;
        //mp.border = 600;
        //mp.speed = 2.66f;
        //mp.type = ScrollType.BounceBack;
        //mp.Calcul();
        //Debug.Log(mp.maxTime);
        //int max = mp.maxTime / 16 + 1;
        //for (int i = 0; i < max; i++)
        //{
        //    mp.Move(16);
        //    Debug.Log(mp.cur);
        //}
    }
    // Start is called before the first frame update
    void Start()
    {
        if (Instance == this)
        {
            UIManager.SetUIData(uiData.bytes);
            HFBase.AddModule<HGUISystem>();
            HFBase.AddModule<HttpManager>();
            //HFBase.AddModule<MainThreadMissionManager>();
            HFBase.OpenSubThread();
            UIPage.LoadPage<StartPage>();
        }
    }

    // Update is called once per frame
    void Update()
    {
        if(Instance==this)
        {
            HFBase.UpdateAll(Time.unscaledDeltaTime);
        }
    }
    private void LateUpdate()
    {
        if (Instance == this)
        {
            HFBase.LateUpdateAll();
        }
    }
    private void OnDestroy()
    {
        if (Instance == this)
        {
            HFBase.ReleaseModule<HttpManager>();
            HFBase.ReleaseModule<KcpManager>();
        }
    }
}
